package com.jz.community.basecomm.mvp;

import java.lang.ref.WeakReference;

/**
 * Created by Tony.Fan on 2018/3/15 11:34
 */
public abstract class BaseMvpPresenter<V extends MVPContract.View> {

    private WeakReference<V> viewRef;

    public void attachView(V view) {
        viewRef = new WeakReference<V>(view);
    }

    protected V getView() {
        return viewRef.get();
    }
    public boolean isViewAttached(){
        return viewRef!=null && viewRef.get()!=null;
    }

    public void detachView() {
        if (viewRef != null) {
            viewRef.clear();
            viewRef = null;
        }
    }
}
